package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.aspect.LogRecord;
import com.woniuxy.dao.CarTypeMapper;
import com.woniuxy.entity.CarType;
import com.woniuxy.service.CarTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarTypeServiceImpl implements CarTypeService {

    @Autowired
    private CarTypeMapper carTypeMapper;
    /**
     * 分页查询
     *
     * @param typeName 车类型
     * @param pageNum  当前页
     * @param pageSize 每页大小
     * @return 分页对象
     */
    @Override
    public PageInfo<CarType> findByPage(String typeName, int pageNum, int pageSize) {
        //1.设置页码和每页大小
        PageHelper.startPage(pageNum,pageSize);
        //2.调用数据Dao层查询
        List<CarType> list = carTypeMapper.findAll(typeName);
        //3.返回PageInfo对象
        return new PageInfo<>(list);
    }

    /**
     * 数据导出excel
     */
    @Override
    public List<CarType> findAll() {
        return carTypeMapper.findAll(null);
    }

    @Override
    public CarType findByCarType(String typeName) {
        return carTypeMapper.findByCarType(typeName);
    }

    /**
     * 添加
     *
     * @param carType
     */
    @LogRecord
    @Override
    public int save(CarType carType) {
        return carTypeMapper.save(carType);
    }

    /**
     * 修改
     *
     * @param carType
     */
    @LogRecord
    @Override
    public int updateById(CarType carType) {
        return carTypeMapper.updateById(carType);
    }

    /**
     * 删除
     *
     * @param id
     */
    @LogRecord
    @Override
    public int deleteById(Integer id) {
        return carTypeMapper.deleteById(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @LogRecord
    @Override
    public int deleteBatch(String[] ids) {
        return carTypeMapper.deleteBatch(ids);
    }

    /**
     * 批量添加数据
     *
     * @param carTypeList
     */
    @Override
    public int insertBatch(List<CarType> carTypeList) {
        return carTypeMapper.insertBatch(carTypeList);
    }
    //远程加载所有车类型方法
    @Override
    public List<CarType> findAllCarType(String typeName) {
        return carTypeMapper.findAllCarType(typeName);
    }
}
